package com.supeng.PMdepot.fragment;

/**
 * Created by sp on 2018/12/10.
 */

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.supeng.PMdepot.R;
import com.supeng.PMdepot.activity.mvp.login.LoginActivity;
import com.supeng.PMdepot.common.Config;
import com.supeng.PMdepot.entity.bak.been.User;
import com.supeng.PMdepot.util.Utils;

/**
 * 左侧滑动栏
 */
public class MenuLeftFragment extends Fragment {
    private TextView tv_name,tv_ip,tv_banben;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_menu, container, false);
        tv_name= (TextView) view.findViewById(R.id.tv_name);
        tv_ip=(TextView) view.findViewById(R.id.tv_ip);
        tv_banben=(TextView) view.findViewById(R.id.tv_banben);
        // 用户退出
        view.findViewById(R.id.layout_logout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                openLogout();
            }
        });

        return view;
    }

    private void openLogout() {
        Config.setUserInfo(new User());
        startActivity(new Intent(getActivity(), LoginActivity.class));
        getActivity().finish();
    }

    @Override
    public void onResume() {
        super.onResume();
        setUserUI();
    }

    /**
     * 设置用户信息UI
     */
    private void setUserUI() {
        tv_name.setText("姓名："+Config.getUserInfo().getUsername());
        tv_banben.setText("版本V"+Utils.getClientVersionName(getActivity()));
        tv_ip.setText(""+Config.getIpAdress());
    }


}
